package com.xingkeduo.delayQueue.model;

import lombok.*;

@AllArgsConstructor
@ToString
@Data
@NoArgsConstructor
public class TaskModel {

    private String id;
    private TaskModelEnum taskModelEnum;

    private int expireTime;

    public Task covertToTask() {
        return new Task(id, taskModelEnum.toString(), System.currentTimeMillis() + this.taskModelEnum.getExpireTime());
    }

    public static TaskModel covertToTaskModel(Task task){
        String value = task.getValue();
        String id = task.getId();
        TaskModelEnum taskModelEnum = TaskModelEnum.valueOf(value);
        return new TaskModel(id,taskModelEnum);
    }

    public TaskModel(String id, TaskModelEnum taskModelEnum) {
        this.id = id;
        this.taskModelEnum = taskModelEnum;
    }
}

